package com.cheyun.netsalev3.viewmodel

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.cheyun.netsalev3.bean.basedata.BaseDataParam
import com.cheyun.netsalev3.bean.basedata.Expchar
import com.cheyun.netsalev3.bean.drive.DriveListInfo
import com.cheyun.netsalev3.repository.DriveListPageRepository
import com.cheyun.netsalev3.utils.MySharedPreferences

class CarDriveDetailsActivity2ViewModel(id:Int) : BaseViewModel() {
    var driveInfo = ObservableField<DriveListInfo>()
    var repository = DriveListPageRepository(0)
    var img = MutableLiveData<String>()

    var baseDataParam: BaseDataParam? = MySharedPreferences.getBaseData()
    init {
        var moth: (detail:DriveListInfo) -> Unit = {
            it.reservehalfStr = it.reservehalf.joinToString(",")
            img.postValue(it.agreement)

            baseDataParam?.apply {
                if (this.drivetype != null) {
                    for (item in this.drivetype) {
                        if(item.id == it.drivetype.toInt())
                            it.drivetypename = item.title
                    }
                }
                if (this.reservetype != null) {
                    for (item in this.reservetype) {
                        if(item.id == it.isreserve?.toInt())
                            it.isreservename = item.title
                    }
                }
            }
            driveInfo.set(it)
        }
        var fail: () -> Unit = {

        }
        repository.getDriveDetail(id,moth,fail)
    }
}
